home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / TextHarvest / TextHarvest-Install.exe / {app} / Help-Comparators.txt < prev    next >
Text File  |  2005-01-21  |  9KB  |  209 lines

  1. <h1>Parse-O-Matic: Comparators</h1>
  2.  
  3. <hl>Note: This is an appendix to the "Parse-O-Matic Scripts" user manual.</hl>
  4.  
  5. <h2>Table of Contents</h2>
  6.  
  7. You can click on any section title below to jump directly to that section.
  8.  
  9.    <a href="#INTRODUC">Introduction</a>
  10.    <a href="#TYPESOFC">Types of Comparators</a>
  11.    <a href="#LITERALC">Literal Comparators</a>
  12.       <a href="#LITEXAMP">Examples</a>
  13.       <a href="#LITCOMSO">Literal Comparisons and Sort Order</a>
  14.    <a href="#NUMERICC">Numerical Comparators</a>
  15.       <a href="#NUMEEXAM">Examples</a>
  16.       <a href="#NUMERISO">Numeric Comparisons and Sort Order</a>
  17.    <a href="#LENGTHCO">Length Comparators</a>
  18.    <a href="#MATCHESC">Comparing Patterns</a>
  19.  
  20. <a name="INTRODUC"><h2>Introduction</h2>
  21.  
  22. A 'comparator' is a parameter used in scripting commands which compares one value to another. For example:
  23. <hl>
  24.   If AreaCode = '416' Output 'Toronto'
  25. </hl>
  26. In this example, a comparison is being made between the variable named AreaCode and the literal '416'. The equals sign is the 'comparator'.
  27.  
  28. Now consider this command:
  29. <hl>
  30.   If AreaCode = '514' Region = 'Montreal'
  31. </hl>
  32. In this case, the first equals sign is a comparator because it is comparing two values. The second equal sign is <b>not</b> a comparator; it is actually the 'Equals' command, which assigns a value to a variable.
  33.  
  34. <a name="TYPESOFC"><h2>Types of Comparators</h2>
  35.  
  36. Parse-O-Matic Scripting supports several types of comparators:
  37. <hl>
  38.   ùùùùùùùùùù  ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  39.   Type         What It Does
  40.   ùùùùùùùùùù  ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  41.   <a href="#LITERALC">Literal</a>     Compares values character by character
  42.   <a href="#NUMERICC">Numerical</a>   Compares the arithmetic values of real or integer numbers
  43.   <a href="#LENGTHCO">Length</a>      Compares the length of one value with a number
  44.   <a href="#MATCHESC">Pattern</a>     Compares a value against a pattern
  45.   ùùùùùùùùùù  ùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùùù
  46. </hl>
  47. These are explained below in more detail.
  48.  
  49. <a name="LITERALC"><h2>Literal Comparators</h2>
  50.  
  51. Here is a list of the literal comparators:
  52. <hl>
  53.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùùù   ùùùùùùùùùùùù
  54.   Comparator   Meaning                Comments
  55.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùùù   ùùùùùùùùùùùù
  56.   =            Identical
  57.   <>           Not identical
  58.   >            Higher                 See Note # 1
  59.   >=           Higher, or identical   See Note # 1
  60.   <            Lower                  See Note # 1
  61.   <=           Lower, or identical    See Note # 1
  62.   ^            Contains
  63.   ~            Does not contain
  64.   Is           Basically the same     See Note # 2
  65.   Longer       Length is longer
  66.   Shorter      Length is shorter
  67.   SameLen      Length is the same
  68.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùùù   ùùùùùùùùùùùù
  69. </hl>
  70. Note # 1:  Depends on sort order. For a discussion of what this means, refer
  71.            to <a href="#LITCOMSO">Literal Comparisons and Sort Order</a>.
  72.  
  73. Note # 2:  The two values are considered basically the same if they
  74.            contain the same text, regardless of upper or lower case, and
  75.            any surrounding whitespace. Thus ' CHESHIRE CAT ' is the
  76.            considered the same as 'Chesire Cat'.
  77.  
  78. <a name="LITEXAMP"><h3>Examples</h3>
  79.  
  80. With some restrictions (discussed later), literal comparators work on both
  81. numeric and alphabetic data. Here are some examples of literal comparisons
  82. that are 'true':
  83. <hl>
  84.   'ABC' <>      'ABCD'        '333' <>      '444'
  85.   'ABC' <=      'ABCD'        '333' <=      '444'
  86.   'ABC' <       'ABCD'        '333' <       '444'
  87.   'ABC' Shorter 'ABCD'        '333' SameLen '444'
  88.   'ABC' >=      'ABC'         'ABC' <>      'CDE'
  89.   'ABC' <=      'ABC'         'ABC' <=      'CDE'
  90.   'ABC' =       'ABC'         'ABC' <       'CDE'
  91.   'ABC' SameLen 'ABC'         'ABC' SameLen 'CDE'
  92.   'ABC' ^       'AB'          'ABC' ~       'CD'
  93.   'ABC' ^       'ABC'         'ABC' ~       'CC'
  94. </hl>
  95. Note especially the ^ (contains) and ~ (does not contain) comparators. These are extremely useful when analyzing data.
  96.  
  97. <a name="LITCOMSO"><h3>Literal Comparisons and Sort Order</h3>
  98.  
  99. Some of the literal comparators compare text according to 'PC-ASCII sort order'. For plain English text, this works fine. However, if your text contains diacritical (accented) characters, you should be aware that some comparisons will not work correctly. For example, the 'A-Umlaut' character appears in the PC-ASCII character set <b>after</b> the PC-ASCII value for 'Z'.
  100.  
  101. <a name="NUMERICC"><h2>Numerical Comparators</h2>
  102.  
  103. Here is a list of the numerical comparators:
  104. <hl>
  105.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  106.   Comparator   Meaning
  107.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  108.   #=           Equal
  109.   #<>          Not equal
  110.   #>           Greater
  111.   #>=          Greater, or equal
  112.   #<           Less than
  113.   #<=          Less than, or equal
  114.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  115. </hl>
  116. Numerical comparators avoid the problem of sort order. For a discussion of this, see <a href="#NUMERISO">Numeric Comparisons and Sort Order</a>.
  117.  
  118. <a name="NUMEEXAM"><h3>Examples</h3>
  119.  
  120. Here are some examples of numeric comparisons (encoded variously with and without surrounding quotes) that are 'true':
  121. <hl>
  122.   345  #<> 567       '1.23'  #<>  '9.87'
  123.  
  124.   345  #<= 567       '1.23'  #<=  '9.87'
  125.  
  126.   567  #>  345       9.87    #>   '1.23'
  127.  
  128.   '3'  #<  '6.2'
  129. </hl>
  130. The last example compares an integer ('3') with a real number ('6.2'). The numeric comparators automatically check if one of the numbers contains a decimal point.
  131.  
  132. In such case, the comparison is performed in 'real number' mode, which imposes the same accuracy restrictions as those imposed by the CalcReal command. This might create a problem if you are comparing a decimal number with a large integer, but this is rarely a cause for worry, since most data analysis tends to compare similar types of numbers.
  133.  
  134. <a name="NUMERISO"><h3>Numeric Comparisons and Sort Order</h3>
  135.  
  136. You can get unintended results when you use literal comparators on numbers. For example, this does not work as you might expect at first glance:
  137. <hl>
  138.   count = count+
  139.   If count >= 2 OutEnd count
  140. </hl>
  141. You might expect this to output any number greater than or equal to '2', but in fact you will get a different result, because the comparison is a literal (text) comparison. In the example above, '2' to '9' are greater or equal to '2', but '10' (which starts with '1') is considered <b>less</b>, as is evident when you sort several numbers alphabetically:
  142. <hl>
  143.   1
  144.   10
  145.   11
  146.   15
  147.   100
  148.   2
  149.   20
  150.   200
  151.   3
  152.   30
  153. </hl>
  154. As you can see, the values 1, 10, 11 and 15 come before '2' when sorted
  155. alphabetically.
  156.  
  157. To compare numbers, you should use the numerical comparators. The correct
  158. way to code the previous example is as follows:
  159. <hl>
  160.   count = count+
  161.   If count #>= 2 OutEnd count
  162. </hl>
  163. Written in this way, numbers greater than or equal to two will be sent to the output file.
  164.  
  165. <a name="LENGTHCO"><h2>Length Comparators</h2>
  166.  
  167. Here is a list of the length comparators:
  168. <hl>
  169.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  170.   Comparator   Meaning
  171.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  172.   Len=         Equal
  173.   Len<>        Not equal
  174.   Len>         Greater
  175.   Len>=        Greater, or equal
  176.   Len<         Less than
  177.   Len<=        Less than, or equal
  178.   ùùùùùùùùùù   ùùùùùùùùùùùùùùùùùùù
  179. </hl>
  180. The length of the value on the left side of the comparator is compared with
  181. a <b>number</b> on the right side of the comparator. For example:
  182. <hl>
  183.   If $Data Len= 0 NullLine = 'Yes'
  184. </hl>
  185. Of course, you could accomplish the same thing with this command:
  186. <hl>
  187.   If $Data = '' NullLine = 'Yes'
  188. </hl>
  189. However, in most cases the length comparisons will save you some coding because you will not have to use the Len command to obtain a variable for comparison.
  190.  
  191. <a name="MATCHESC"><h2>Comparing Patterns</h2>
  192.  
  193. The Matches comparator compares a value against a pattern that uses "regular expression" syntax (explained later). For example:
  194. <hl>
  195.   If MyVar Matches 'c[aou]t' GotMatch = 'Yes'
  196. </hl>
  197. This will set the variable GotMatch to 'Yes' if MyVar contains 'cat', 'cot' or 'cut' (case is ignored).
  198.  
  199. The pattern uses "regular expression" syntax and must be the second item in the comparison.
  200.  
  201. In order for the comparison to be "true", the item being compared to the pattern must match the pattern precisely ù the Matches comparator does not look for substrings.
  202.  
  203. If you want to allow a substring to match, use the Comprises comparator. For example:
  204. <hl>
  205.   If MyVar Comprises 'c[ao]t' GotMatch = 'Yes'
  206. </hl>
  207. This will set GotMatch to 'Yes' if MyVar includes either the word 'cat' or 'cot'.  Thus, the strings 'He had a cat' and 'He had a cot' both Comprise the pattern, as do the strings 'cat', 'cot', 'Cat', 'scatter' and so on.
  208.  
  209. Click <a href="pommel://Help-RegExp.txt">here</a> to learn about regular expression syntax.